package xyz.lwm.lazycat.utility;

import lombok.Getter;

@Getter
public class R<T> {

    private final int code;

    private final T data;

    private final String msg;

    private final String errMsg;

    private R(int code, T data, String msg, String errMsg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.errMsg = errMsg;
    }

    public boolean isSuccess() {
        return code == 200;
    }

    public static <T> R<T> ok(T data) {
        return new R<>(200, data, "success", null);
    }

    public static <T> R<T> ok(T data, String msg) {
        return new R<>(200, data, msg, null);
    }

    public static <T> R<T> fail(String errMsg) {
        return new R<>(500, null, null, errMsg);
    }

}
